var express = require('express');
var router = express.Router();
var userDao = require('../dao/user/userDao');

var sessionLog = require('./sessionLog');   //验证session

/* 登录 */
router.get('/login', function(req, res, next) {
    res.render('user/login.html', {});
});
router.post('/login',function(req,res,next){
    userDao.login(req, res, next);
});
/* 退出登录 */
router.get('/logout',function(req,res,next){
    delete req.session.user;
    res.render('user/login.html', {});
});

/* 注册 */
router.get('/register', function(req, res, next) {
    res.render('user/register.html', { title: '注册', result:[]});
});
/* 注册
* userName 用户名*
* passWord 密码*
* nickName 昵称*
* sex 昵称默认2  1男 0女 2未填写
* */
router.post('/register',function(req,res,next){
    userDao.register(req, res, next);
});

/* 修改用户
* id   用户ID*
* */
router.get('/edit', sessionLog, function(req, res, next) {
    userDao.editId(req, res, next);
});
/* 修改用户
* id   用户ID*
* nickName 昵称
* sex 昵称默认2  1男 0女 2未填写
* */
router.post('/edit', sessionLog, function(req, res, next) {
    userDao.edit(req, res, next);
});


module.exports = router;
